package com.dahuyou.netty.customercodec.client;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

/**
 * 客户端通道初始化类
 */
public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel channel) throws Exception {
//        System.out.println("连接到server成功，通道id为：" + channel.id());


        // 解码转String，注意调整自己的编码格式GBK、UTF-8
//        channel.pipeline().addLast(new StringDecoder(Charset.forName("GBK")));
//        channel.pipeline().addLast(new MyDecoder());
        // 解码转String，注意调整自己的编码格式GBK、UTF-8
//        channel.pipeline().addLast(new StringEncoder(Charset.forName("GBK")));
/*
        channel.pipeline().addLast(new StringDecoder());
        channel.pipeline().addLast(new MyEncoder());
*/
        // 在管道中添加我们自己的接收数据实现方法
        channel.pipeline().addLast(new MyClientHandler());

    }
}
